﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestTCPContract
{
    public class DrawResp
    {
        /// <summary>
        /// 128
        /// </summary>
        [CPPEI.Net.Field(Order = 1, Length = 128)]
        public string Message2 { get; set; }

        /// <summary>
        /// 32
        /// </summary>
        [CPPEI.Net.Field(Order = 2, Length = 32)]
        public string Message { get; set; }

        /// <summary>
        /// 4
        /// </summary>
        [CPPEI.Net.Field(Order = 3)]
        public int Value { get; set; }

        public static byte[] ToData(DrawResp model)
        {
            byte[] data = new byte[36 + 128];
            int offset = 0;
            CPPEI.Net.BufferUtil.StringToBuffer(model.Message2, data, ref offset, 128);
            CPPEI.Net.BufferUtil.StringToBuffer(model.Message, data, ref offset, 32);
            CPPEI.Net.BufferUtil.IntToBuffer(model.Value, data, ref offset);

            return data;
        }

        public static DrawResp FromData(byte[] data)
        {
            DrawResp model = new DrawResp();
            int offset = 0;
            model.Message2 = CPPEI.Net.BufferUtil.StringFromBuffer(data, ref offset, 128);
            model.Message = CPPEI.Net.BufferUtil.StringFromBuffer(data, ref offset, 32);
            model.Value = CPPEI.Net.BufferUtil.IntFromBuffer(data, ref offset);
            return model;
        }
    }
}
